function promiseAll(promises) {
  if(!Array.isArray(promises)) {
    return Promise.reject(new TypeError('参数必须是数组'))
  }
  if(promises.length===0) {
    return Promise.resolve([])
  }
  let count=0;
  const result = [];
  return new Promise((resolve, reject)=> {
    promises.forEach((promise, index)=>{
      Promise.resolve(promise).then(
        res=>{
          count++;
          result[index]=res;
          count==promises.length && resolve(result)
        },
        rej=>{
          reject(rej)
        }
      )
    })
  })
}